const { DataTypes } = require('sequelize')
const mysql = require('../config/db')
require('dotenv').config()

const Users = mysql.define(
  'users',
  {
    id: {
      type: DataTypes.BIGINT,
      autoIncrement: true,
      primaryKey: true,
    },
    username: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    email: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    password: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    avatar: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    emailVerified: {
      type: DataTypes.BOOLEAN,
      allowNull: true,
    },
    lastLogin: {
      type: DataTypes.DATE,
      allowNull: true,
    },
    loginIp: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    displayName: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    contactJson: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: 'JSON格式的contact信息',
    },
    bio: {
      type: DataTypes.TEXT,
      allowNull: true,
    },
    website: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    location: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    role: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    isBanned: {
      type: DataTypes.BOOLEAN,
      allowNull: true,
    },
    deletedAt: {
      type: DataTypes.DATE,
      allowNull: true,
    },
    tags: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: 'JSON格式的tags信息',
    },
    about: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: '关于我的信息',
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: true,
    },
    milestone: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: 'JSON格式的milestone信息',
    },
    skillJson: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: 'JSON格式的skill信息',
    },
  },
  {
    timestamps: true,
    paranoid: true,
    deletedAt: process.env.DELETED_AT,
    tableName: 'users',
  },
)

module.exports = Users
